//
//  XJYBaseViewController.m
//  ShopMall
//
//  Created by XJY on 17/1/19.
//  Copyright © 2017年 XinJinYing. All rights reserved.
//

#import "XJYBaseViewController.h"
#import "HttpTool.h"
#import "UIView+Toast.h"
#import <SVProgressHUD.h>

@interface XJYBaseViewController ()

@end

@implementation XJYBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MainColor;
}

- (void)getWithPath:(NSString *)path params:(NSDictionary *)params success:(HttpSuccessBlock)success failure:(HttpFailureBlock)failure
{
    [SVProgressHUD show];
    [HttpTool getWithPath:path params:params success:^(id json) {
        [SVProgressHUD dismiss];
        if (success) {
            success(json);
        }
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self showTostMessage:@"网络异常，请检查网络"];
        if (failure) {
            failure(error);
        }
    }];
}

- (void)postWithPath:(NSString *)path params:(NSDictionary *)params success:(HttpSuccessBlock)success failure:(HttpFailureBlock)failure
{
    [SVProgressHUD show];
    [HttpTool postWithPath:path params:params success:^(id json) {
        [SVProgressHUD dismiss];
        if (success) {
            success(json);
        }
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self showTostMessage:@"网络异常，请检查网络"];
        if (failure) {
            failure(error);
        }
    }];
}

- (void)showTostMessage:(NSString *)tost
{
    [self.view makeToast:tost duration:1.5 position:@"center"];
}
@end
